<?php
/**
 * 文件上传接口
 */
namespace app\admin\controller\sys;
use \app\admin\controller\Auth;
class Images extends Auth{
    
    /**
     * 读取相册
     */
    public function ajaxAlbum(){        
        try{
            $showTag = input('showtag','my');// my 或者 server 
            $type = input('type','editor');            
            $userInfo = $this->getUser()->getInfo();        
            $ImageAlbum =  new \logic\sys\images\ImageAlbum();
            $where = [
                'utype' => 3,
                'uid'   => $userInfo['msiteid'],
                'status'=> 1,
            ];
            $myAlbum = $ImageAlbum->getAlbumList($where);
            $publicAlbum = $ImageAlbum->getSitePublicAlbum();
            
            $Image = new \logic\sys\images\Image();
            $iWhere = [
                'page'  => input('page',1),
                'limit' => 20,
                'status'=>1
            ];
            if( $showTag == 'my' ){
                if( $type ){
                    $type = strtolower($type);
                    foreach( $myAlbum as $key=>$val){
                        if( strtolower($val['tag']) == $type ){
                            $albumId = $val['id'];
                            break;
                        }
                    }
                }
                if( $albumId ) $iWhere['albumid'] = $albumId;
                $imageList = $Image->getSelfList($iWhere);
            }else{
                if( $type ){
                    $type = strtolower($type);
                    foreach( $publicAlbum as $key=>$val){
                        if( strtolower($val['tag']) == $type ){
                            $albumId = $val['id'];
                            break;
                        }
                    }
                }
                if( $albumId ) $iWhere['albumid'] = $albumId;
                $imageList = $Image->getPublicList($iWhere);
            }
            
            $data = ['my'=> $myAlbum,'server'=>$publicAlbum,'img'=> $imageList,'albumid'=> $albumId ?:0];
           // dump($data);
            return $this->success( '成功','',$data);
            
        }catch( \think\Exception $e){
            return $this->error( $e->getMessage());
        }           
    }
    
    /**
     * 读取相册下面的图片
     */
    public function ajaximg(){
        $showTag = input('showtag');// my 或者 server 
        $albumid = input('albumid',0); // 相册ID
        try{
            $iWhere = [
                'page'  => input('page',1),
                'limit' => 20,
                'status'=>1
            ];
            if( $albumid )  $iWhere['albumid'] = $albumid;
            $Image = new \logic\sys\images\Image();
            if( $showTag == 'my' ){
                $imageList = $Image->getSelfList($iWhere);
            }else{
                $imageList = $Image->getPublicList($iWhere);
            }
            return $this->success( '成功','',$imageList);
        }catch( \think\Exception $e){
            return $this->error( $e->getMessage());
        }
        
    }
    
    
}